package com.gionee.navil.lockscreen.shortcut;

import java.io.File;
import java.net.URI;

import com.gionee.navil.lockscreen.R;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;

@SuppressWarnings("deprecation")
public class ImageScaleActivity extends Activity {
    /** Called when the activity is first created. */
    MyImageView image;

    Bitmap mBitmap = null;
    ImageView mImageView = null;
    String mImagePath = null;
    private ActionBar mActionBar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        
        setContentView(R.layout.image_scale);
        Intent intent = this.getIntent();
        mImagePath = intent.getStringExtra("imagePath");

//        mActionBar = getActionBar();
////        mActionBar.setDisplayHomeAsUpEnabled(true);
//        mActionBar.setDisplayShowHomeEnabled(false);
//        mActionBar.setDisplayShowTitleEnabled(false);
//        mActionBar.show();

        mImageView = (ImageView) findViewById(R.id.scaleImg);
//        image = new MyImageView(this);
//        mBitmap = BitmapFactory.decodeFile(imagePath);
//        image.setScreenSize(this, getWindowManager().getDefaultDisplay().getWidth(), getWindowManager()
//                .getDefaultDisplay().getHeight(), mBitmap);
//        mImageView.setImageBitmap(mBitmap);
        mImageView.setImageURI(Uri.fromFile(new File(mImagePath)));
//        setContentView(image);
    }

    private static final int DRAG = 10;
    private static final int NULL = 0;
    private static final int SCALE = 11;
    private int mode;
    private float mStartX;

//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        // TODO Auto-generated method stub
//        switch (event.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                Log.i("lin", "down");
//                mode = DRAG;
//
//                mStartX = event.getRawX();
//                image.init(event);
//                break;
//            case MotionEvent.ACTION_MOVE:
//                if (mode == SCALE)
//                    image.zoom(event);
//                if (mode == DRAG) {
//                    image.drag(event);
//                    return true;
//                }
//                break;
//            case MotionEvent.ACTION_UP:
//                Log.i("lin", "up");
//                if (mode == SCALE) {
//                    image.backScale();
//                    mode = NULL;
//                } else if (mode == DRAG) {
//                    image.backDrag();
//                }
//                break;
//            case MotionEvent.ACTION_POINTER_1_DOWN:
//                Log.i("lin", "down1");
//                break;
//            case MotionEvent.ACTION_POINTER_2_DOWN:
//                Log.i("lin", "down2");
//                image.getOldDist(event);
//                mode = SCALE;
//                break;
//            case MotionEvent.ACTION_POINTER_2_UP:
//                Log.i("lin", "up2");
//
//            default:
//                break;
//        }
//
//        return super.onTouchEvent(event);
//    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        getMenuInflater().inflate(R.menu.image_scale_menu, menu);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
//        menu.findItem(R.id.menu_delete).setVisible(true);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return true;
    }

    private float calculate(float x1, float x2) {
        float pz = x1 - x2;// 计算两点间的距离
        return pz;
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        if (mBitmap != null && !mBitmap.isRecycled()) {
            mBitmap.recycle();
            mBitmap = null;
        }
        super.onDestroy();
    }
}